package androidx.activity;

import android.app.Activity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import java.lang.reflect.Field;
import o.kp.e;
import o.kq;
import o.kv;

@RequiresApi(19)
final class ImmLeaksCleaner implements kq {
    private static Field ˊ;
    private static Field ˋ;
    private static Field ˎ;
    private static int ˏ = 0;
    private Activity ॱ;

    ImmLeaksCleaner(Activity activity) {
        this.ॱ = activity;
    }

    public void ˊ(@NonNull kv kvVar, @NonNull e eVar) {
        if (eVar == e.ON_DESTROY) {
            if (ˏ == 0) {
                ˎ();
            }
            if (ˏ == 1) {
                InputMethodManager inputMethodManager = (InputMethodManager) this.ॱ.getSystemService("input_method");
                try {
                    Object obj = ˊ.get(inputMethodManager);
                    if (obj != null) {
                        synchronized (obj) {
                            try {
                                View view = (View) ˎ.get(inputMethodManager);
                                if (view == null) {
                                } else if (view.isAttachedToWindow()) {
                                } else {
                                    try {
                                        ˋ.set(inputMethodManager, null);
                                        inputMethodManager.isActive();
                                    } catch (IllegalAccessException e) {
                                    }
                                }
                            } catch (IllegalAccessException e2) {
                            } catch (ClassCastException e3) {
                            }
                        }
                    }
                } catch (IllegalAccessException e4) {
                }
            }
        }
    }

    @MainThread
    private static void ˎ() {
        try {
            ˏ = 2;
            ˎ = InputMethodManager.class.getDeclaredField("mServedView");
            ˎ.setAccessible(true);
            ˋ = InputMethodManager.class.getDeclaredField("mNextServedView");
            ˋ.setAccessible(true);
            ˊ = InputMethodManager.class.getDeclaredField("mH");
            ˊ.setAccessible(true);
            ˏ = 1;
        } catch (NoSuchFieldException e) {
        }
    }
}
